<?php
$this->load->view('header');

if (strlen($this->session->flashdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->flashdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<script type="text/javascript">
    function search_data() {
        $.post("<?= site_url() ?>setup/search_room", {
            search_by_room: $('#search_by_room').val(),
            search_by_floor: $('#search_by_floor').val(),
            search_by_type: $('#search_by_type').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }

    function load_page_room(page, ipp) {
        $.post("<?= site_url() ?>setup/load_page_room", {
            page: page,
            ipp: ipp,
            search_by_room: $('#search_by_room').val(),
            search_by_floor: $('#search_by_floor').val(),
            search_by_type: $('#search_by_type').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }

    function activation_room(room_id, cond) {
        var page = $('#page_val').val();
        var ipp = $('#ipp_val').val();
        var str = 'Are you sure to deactivate this room?';
        if(cond!='Y'){
            str = 'Are you sure to activate this room?';
        }
        var cek = confirm(str);
        if (cek) {
            $.post("<?= site_url() ?>setup/activation_room", {
                room_id: room_id,
                cond : cond
            },
            function(data) {
                load_page_room(page, ipp);
            });
        }
    }

    function edit_data(room_id) {		
        $.post("<?= site_url() ?>setup/edit_room", {room_id: room_id}, function(data) {
            $('#loader').html(data);
        });
    }
	
	function view_detail(room_id,type){
		$.post("<?= site_url() ?>setup/view_detail", {room_id: room_id, type: type}, function(data) {
            $('#loader').html(data);
        });
	}
	
	function add_detail(room_id,type){		
		$.post("<?= site_url() ?>setup/add_detail", {room_id: room_id, type: type}, function(data) {
            $('#loader').html(data);
        });
	}

    function add_data() {
        $.post("<?= site_url() ?>setup/add_room", function(data) {
            $('#loader').html(data);
        });
    }
	
	function add_data_item() {
        $.post("<?= site_url() ?>setup/add_room_item", function(data) {
            $('#loader').html(data);
        });
    }
	
	function delete_data(room_name, room_id){		
		if (confirm("Apakah Anda Yakin Ingin Delete Room '"+ room_name +"' ?")){
			$.post("<?= site_url() ?>setup/delete_room", {room_name: room_name, room_id: room_id}, function(data) {
				window.location = '<?php echo base_url();?>setup/room';
			});
		}
	}

</script>

<div id="loader" class="container">
	<form class="form-horizontal" role="form" method="post" action="#">
	<div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Search Room</b></h4>
				</div>
				<div class="panel-body">					
					<div class="col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Room Name</p></label>
							<div class="col-md-7">
								<input type="text" class="form-control input-sm" id="search_by_room" name="search_by_room">
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Room Floor</p></label>
							<div class="col-md-4">
								<select name="search_by_floor" id="search_by_floor" class="form-control input-sm">                         
									<option value="0">- select -</option>
								<?php
									foreach($floor_select as $floor_select => $key)
									{
										echo '<option value="'.$key['MST_FLOOR_DESC'].'">'.$key['MST_FLOOR_DESC'].'</option>';
									}
								?>							
								</select>
							</div>
						</div>
					</div>
					<div class="col-sm-6 col-md-5">
						<div class="form-group">
							<label class="col-md-5"><p class="text-left">Type Name</p></label>
							<div class="col-md-7">
								<select name="search_by_type" id="search_by_type" class="form-control input-sm">                         
									<option value="0">--- select ---</option>
								<?php
									foreach($type_select as $type_select => $key)
									{
										echo '<option value="'.$key['MST_TYPE_ID'].'">'.$key['MST_TYPE_DESC'].'</option>';
									}
								?>							
								</select>
							</div>
						</div>						
						<div class="form-group">
							<div class="col-md-5"><label for="button" class="control-label">&nbsp;</label></div>
							<div class="col-md-3">
								<button type="button" class="btn btn-primary btn-sm" onclick="search_data();">
								<!--span class="glyphicon glyphicon-search"></span--> Search</button>
							</div>
							<div class="col-md-3">
								<button type="reset" class="btn btn-default btn-sm">
								<!--span class="glyphicon glyphicon-refresh"></span--> Clear</button>
							</div>
						</div>
					</div>					
				</div>
			</div>
			<div class="panel-body well">
				<div class="col-md-6">
					<div class="form-group">
						<div class="col-md-4">
							<button type="button" class="btn btn-success btn-sm" onclick="add_data();">
							<!--span class="glyphicon glyphicon-plus"></span--> Add Room</button>
						</div>
						<div class="col-md-5">
							<button type="button" class="btn btn-success btn-sm" onclick="add_data_item();">
							<!--span class="glyphicon glyphicon-plus"></span--> Add Master Item</button>
						</div>
					</div>
				</div>
				<div id="tablecontent" class="col-md-12">						
					<div class="form-group">
						<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
								<thead>
									<tr>
										<th class="tblhead" style="width:10px;text-align:center;">No</th>
										<th class="tblhead" style="width:15px;text-align:center;">Type Name</th>
										<th class="tblhead" style="width:15px;text-align:center;">Room Name</th>
										<th class="tblhead" style="width:15px;text-align:center;">Floor</th>
										<th class="tblhead" style="width:15px;text-align:center;">Detail</th>
										<th class="tblhead" style="width:15px;text-align:center;">Status</th>
										<th class="tblhead" style="width:15px;text-align:center;">Action</th>
									</tr>
								</thead>
								<tbody>
									<?php
									if (empty($list_data)) {
										?>
										<tr><td colspan="9" style="text-align:center">No Data Available</td></tr>
										<?php
									} else {
										foreach ($list_data as $row) {
											?>
											<tr>
												<?php
												$room_id 		= $row["MST_CATEGORY_ID"];
												$type_name 		= $row["MST_TYPE_DESC"];
												$floor_desc 	= $row["MST_FLOOR_DESC"];
												$status 		= $row["MST_CATEGORY_STATUS"];
												$category_name 	= $row["MST_CATEGORY_DESC"];
												$type 			= $row["MST_TYPE_ID"];
												$floor_id 		= $row["MST_FLOOR_ID"];
												$room_status 	= ($status == 'Y') ? 'Active' : 'Not Active';
												?>

												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $row["RECNUM"]; ?>.</td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $type_name; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $category_name; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $floor_desc; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<a class="btn btn-sm btn-info" href="#" onclick="view_detail('<?php echo $room_id ?>','<?php echo $type ?>');">
														<!--span class="glyphicon glyphicon-eye-open"></span--> View</a>
												</td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<?php if($status=='Y') :?>
														<a class="btn btn-sm btn-primary" href="#" onclick="activation_room('<?php echo $room_id ?>', '<?php echo $status ?>');">
														<!--span class="glyphicon glyphicon-ok"></span--> <?php echo $room_status; ?></a>
													<?php else: ?>
														<a class="btn btn-sm btn-danger" href="#" onclick="activation_room('<?php echo $room_id ?>', '<?php echo $status ?>');">
														<!--span class="glyphicon glyphicon-ban-circle"></span--> <?php echo $room_status; ?></a>
													<?php endif; ?>
												</td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data('<?php echo $room_id ?>');">
														<!--span class="glyphicon glyphicon-edit"></span--> Edit</a>
													<!--a class="btn btn-sm btn-danger" href="#" onclick="delete_data('< ?php echo $category_name ?>', '< ?php echo $room_id ?>');"-->
														<!--span class="glyphicon glyphicon-remove"></span> Delete</a-->
												</td>
											</tr>
											<?php
										}
									}
									?>
								</tbody>
							</table>
						</div>
					</div>
					<div class="form-group">
						<div id="mypaging">
							<?php
							echo $paging;
							echo $jump_page;
							echo $ipp;
							?>
						</div>								
					</div>						
				</div>
			</div>
		</div>
	</div>
	</form>	
</div>

<?php $this->load->view('footer'); ?>